package as.myapplication;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private TabLayout tabNews;
    private ViewPager vpNews;
    private List<Fragment> mFragments ;
    private String[] title;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mFragments = new ArrayList<>();
        mFragments.add(new Fragment1());
        mFragments.add(new Fragment2());
        title = new String[]{"基本信息","维护信息"};


        tabNews = (TabLayout) findViewById(R.id.tab_news);
        vpNews = (ViewPager) findViewById(R.id.vp_news);
        initData();
    }

    private void initData() {
        vpNews.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(),mFragments,title));
        tabNews.setupWithViewPager(vpNews);
    }
}
